<template>
  <!-- 还款查询 -->
  <section class="page record-query">
    <data-form :model="searchModel" @onSearch="refreshData" :page="pageService" @handleResetForm="handleResetForm">
      <template slot="inputs">
        <el-form-item label="订单编号" prop="caseNumber">
          <el-input v-model="searchModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model="searchModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobileNo">
          <el-input v-model="searchModel.mobileNo"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="searchModel.idCard"></el-input>
        </el-form-item>
        <el-form-item label="催收员/受托方" prop="name">
          <el-input v-model="searchModel.name"></el-input>
        </el-form-item>
        <el-form-item label="还款时间" prop="createTime">
          <el-date-picker type="daterange" :editable="false" v-model="searchModel.createTime" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="还款类型" prop="caseRepaymentMethod">
          <el-select placeholder="请选择" v-model="searchModel.caseRepaymentMethod">
            <el-option v-for="{index,name,code} in $dict.getDictData('CaseRepaymentMethod')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="案件金额" prop="caseMoney">
          <number-range v-model="searchModel.caseMoney" :isInteger="true"></number-range>
        </el-form-item>
      </template>
    </data-form>

    <data-box :data="dataSet" @onPageChange="queryRepaymentRecord" :page="pageService">
      <template slot="buttons">
        <el-button @click="exportData" v-auth="235">导出</el-button>
      </template>
      <template slot="columns">
        <!--数据列区域-->
        <el-table-column prop="caseNumber" label="订单编号" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="personalName" label="客户姓名" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="mobileNo" label="手机号" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号码" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="name" label="催收员/受托方" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="caseMoney" label="案件金额(元)" :min-width="$helper.getColumnWidth(4)"></el-table-column>
        <el-table-column prop="overdueAmount" label="欠款金额(元)" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="repayAmount" label="还款金额" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="entryTime" label="还款时间" :formatter="(row) => $filter.dateTimeFormat(row.entryTime)" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="caseRepaymentMethod" label="还款类型" :formatter="(row) => $filter.dictConvert(row.caseRepaymentMethod,'CaseRepaymentMethod')" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
        </el-table-column>
      </template>
      <p slot="footer">{{`查询结果统计：当前还款总金额 ${$filter.toThousands(totalInfo.totalAmount)}元`}}</p>
    </data-box>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Auth, Layout, Dependencies } from "~/core/decorator";
import { PageService } from "~/utils/page.service";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import { SortService } from "~/utils/sort.service";
import NumberRange from "~/components/common/number-range.vue";
import { CaseRepaymentService } from "~/services/domain-service/case-repayment.service";
import { namespace, Getter, Mutation } from "vuex-class";
import { UserService } from "~/services/management-service/user.service";


const CollectionExecutionModule = namespace('collection-execution');
@Auth(2307)
@Layout("workspace")
@Component({
  components: {
    NumberRange
  }
})
export default class RecordQuery extends Vue {

  @Dependencies(PageService) private pageService: PageService;

  @Dependencies(SortService) private sortService: SortService;

  @Dependencies(CaseRepaymentService)
  private caseRepaymentService: CaseRepaymentService;

  @Dependencies(UserService)
  private userService: UserService;

  @Getter
  private departmentData;

  @Getter
  private isSupperAdmin;

  private totalInfo: any = {};

  private searchModel: any = {
    caseNumber: "",
    personalName: "",
    mobileNo: "",
    idCard: "",
    name: "",
    createTime: [],
    caseRepaymentMethod: "",
    caseMoney: { min: '', max: '' }
  };

  private dataSet: any[] = [];

  private userDataSet = [];

  private userModel: any = {
    deptCode: ""
  };
  private queryTotalAmount() {
    this.caseRepaymentService
      .caseRepaymentAmount(this.searchModel)
      .subscribe(data => (this.totalInfo = data));
  }

  private queryRepaymentRecord() {
    this.caseRepaymentService
      .selectCaseRepayment(this.searchModel, this.pageService)
      .subscribe(data => (this.dataSet = data));
  }

  private refreshData() {
    this.queryRepaymentRecord();
    this.queryTotalAmount();
  }

  private handleResetForm() {
    this.searchModel.caseMoney = { min: '', max: '' }
  }

  private mounted() {
    this.refreshData();
  }
  /**
   * 导出
   */
  private exportData() {
    this.caseRepaymentService
      .exportCaseRepayment(this.searchModel)
      .subscribe(data => {
        this.$common.downloadFile(data.url, data.originalName)
        this.$message.success('导出成功!')
      }

      );

  }
}
</script>
<style lang="less">
</style>
